import * as index from '@/api/index.js'
export default {
	data() {
		return {
			cateList:[],
			token:'',
			loginForm: {
				code: '',
				mobilecode: ''
			},
		}
	},
	
	onShow() {
		this.token = uni.getStorageSync('token')
	},
	onLoad(option) {
		this.getwxCode()
		this.getCateList()
	},

	methods: {
		getCateList(){
			index.getCateList().then(res=>{
				this.cateList = res.data
			})
		},
		jump(){
			this.$tools.navigate('/pages/placeOrder/index')
		},
		getwxCode() {
			let that = this
			uni.login({
				provider: 'weixin',
				onlyAuthorize: true,
				success: function(loginRes) {
					that.loginForm.code = loginRes.code
				}
			});
		},
		getPhoneNumber(e) {
			this.loginForm.mobilecode = e.detail.code
			this.wxLogin()
		},
		wxLogin() {
			let that = this
			if (this.loginForm.mobilecode && this.loginForm.code) {
				index.wxmobile(this.loginForm).then(res => {
					// if (res.data.userinfo.avatar == '' || res.data.userinfo.nickname == '') {
					// 	that.$tools.navigate('/pages/user/userinfo/index')
					// }
					uni.setStorage({
						key: 'userInfo',
						data: res.data.userinfo,
						success: function() {
						}
					})
					uni.setStorage({
						key: 'token',
						data: res.data.userinfo.token,
						success: function() {
							that.getwxCode()
							that.token = res.data.userinfo.token
							that.jump()
						}
					});
				})
			}
		},
	}
}